<?php
/*
* Main controller
*/
class ControllerMain
{
	protected $className; //Name of call class
	protected $templateDir; //Path to folder with templates
	protected $request; //Form object
	protected $get = array(); // clear $_GET array
	protected $post = array(); // clear $_POST array
	protected $header; //object of header controller
	protected $sidebar; //object of sidebar controller
	protected $mainTemplate; //Path to main template
	protected $template; //html-template
	protected $keys = array();//keys for template
	
	public function __construct()
	{
		$this->setClassName(); //Set name of call class
		$this->setTemplateDir(); //Set path to folder with template
		$this->getRequest(); //Get POST-GET request
		$this->setMainTemplate(); //Set path to main template
		$this->setBoardroomNumber(); //Set constant with boardroom number;
		$this->callHeader(); //Call header controller
		$this->callSidebar(); //Call sidebar controller
		View::setTemplate($this->mainTemplate); //Set main template for VIEW
	}
	
	//Set name of call class
	protected function setClassName()
	{
		$this->className = substr(get_class($this),strlen('Controller'));
		$this->className = strToLower($this->className);
	}
	
	//Set path to folder with template
	protected function setTemplateDir()
	{
		$this->templateDir = TEMPLATES_DIR.$this->className.'/';
	}
	
	//Get POST-GET request
	protected function getRequest()
	{
		$this->request = new FormObj();
		$this->get = $this->request->getGet(); //array with $_GET data
		$this->post = $this->request->getPost(); //array with $_POST data
	}
	
	//Set path to main template
	protected function setMainTemplate()
	{
		$this->mainTemplate = MAIN_TEMPLATE;
	}
	
	//Set constant with boardroom number;
	protected function setBoardroomNumber()
	{
		if(isset($this->get['boardroom']) && !empty($this->get['boardroom']))
		{
			if($this->get['boardroom'] <= BOARDROOM_COUNT)
			{
				define('BOARDROOM_NUMBER',$this->get['boardroom']); //Set number
			}
			else
			{
				define('BOARDROOM_NUMBER',1); //Default number of boardroom	
			}
		}
		else
		{
			define('BOARDROOM_NUMBER',1); //Default number of boardroom
		}
	}
	
	//Call header controller
	protected function callHeader()
	{

		$this->header = new ControllerHeader();	
	}
	
	//Call sidebar controller
	protected function callSidebar()
	{
		$this->sidebar = new ControllerSidebar();
	}
	
	/*
	*Method clear data 
	*
	*
	*return data
	*/
	protected function clearData($data, $type='string')
	{
		switch($type)
		{
			case 'string':
				$data = (string)$data; 
				$data = strip_tags(stripslashes($data));
				$data = trim($data);
				return $data;
				break;
				
			case 'integer':
				$data = (int)$data;
				$data = abs($data);
				return $data;
				break;
				
			case 'float':
				$data = (float)$data;
				$data = abs($data);
				return $data;
				break;
		}
	}	
}